package asher.dotatbg.http.parser;

import asher.dotatbg.http.bean.HttpHeader;

/**
 * 解析HttpHeader信息的静态工具类
 * @author AsherYuan
 *
 */
public class HttpHeaderParser {

	/**
	 * 将浏览器发来的http协议信息，作为一个httpheader单元来解析，返回一个HttpHeader的对象实例，以供后续调用
	 * 目前主要解析出uri，辅助功能后续添加
	 * @param headStr
	 * @return
	 */
	public static HttpHeader parserHeader(String headStr) {
		HttpHeader header = new HttpHeader();
		
		String[] lines = headStr.split("\r\n");
		if(lines != null && lines.length > 0) {
			String[] requsetBaseInfo = lines[0].split(" ");
			header.setHttpRequestMethod(requsetBaseInfo[0]);
			header.setHttpRequestUri(requsetBaseInfo[1]);
			header.setHttpRequestProtocal(requsetBaseInfo[2]);
		}
		return header;
	}
}


//以下为浏览器传来的需要的解析的文本样例
//GET /DotaTBG/abc HTTP/1.1
//Host: 127.0.0.1:8086
//User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0) Gecko/20100101 Firefox/10.0
//Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
//Accept-Language: zh-cn,zh;q=0.5
//Accept-Encoding: gzip, deflate
//Connection: keep-alive